package com.nmsl.controller;

import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.core.page.TableDataInfo;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.domain.GyfDoctorSchedule;
import com.nmsl.mapper.GyfDoctorScheduleMapper;
import com.nmsl.service.IGyfDoctorScheduleService;
import com.nmsl.util.R.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


import static com.nmsl.common.core.domain.AjaxResult.success;
import static com.nmsl.common.utils.PageUtils.startPage;

@RequestMapping("/ds")
@RestController
public class GyfDoctorScheduleController extends BaseController {
    @Autowired
    private GyfDoctorScheduleMapper gyfDoctorScheduleMapper;

    //通过医生id和预约日期来查询  排班信息
    @GetMapping("/selectByIdAndDate")
    public R selectByDoctorIdAndDate(int doctorId, String date){
        GyfDoctorSchedule gyfDoctorSchedule = gyfDoctorScheduleMapper.selectByDoctorIdAndDate(doctorId, java.sql.Date.valueOf(date));
        if(gyfDoctorSchedule != null){
            return R.ok(gyfDoctorSchedule);
        }else{
            return R.fail("没有查到任何数据");
        }
    }

    @Autowired
    private IGyfDoctorScheduleService gyfDoctorScheduleService;

    /**
     * 查询医生排班列表
     */
    @PreAuthorize("@ss.hasPermi('gyf:paiban_management:list')")
    @GetMapping("/list")
    public TableDataInfo list(GyfDoctorSchedule gyfDoctorSchedule)
    {
        gyfDoctorSchedule.setScheduleId(0);
        System.out.println("打印一下传来的参数");
        System.out.println(gyfDoctorSchedule);
        startPage();
        List<GyfDoctorSchedule> list = gyfDoctorScheduleService.selectGyfDoctorScheduleList(gyfDoctorSchedule);
        System.out.println("打印一下查出来的信息");
        System.out.println(list);
        return getDataTable(list);
    }


    /**
     * 导出医生排班列表
     */
    @PreAuthorize("@ss.hasPermi('gyf:paiban_management:export')")
    @Log(title = "医生排班", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GyfDoctorSchedule gyfDoctorSchedule)
    {
        List<GyfDoctorSchedule> list = gyfDoctorScheduleService.selectGyfDoctorScheduleList(gyfDoctorSchedule);
        ExcelUtil<GyfDoctorSchedule> util = new ExcelUtil<GyfDoctorSchedule>(GyfDoctorSchedule.class);
        util.exportExcel(response, list, "医生排班数据");
    }

    /**
     * 获取医生排班详细信息
     */
    @PreAuthorize("@ss.hasPermi('gyf:paiban_management:query')")
    @GetMapping(value = "/{scheduleId}")
    public AjaxResult getInfo(@PathVariable("scheduleId") Long scheduleId)
    {
        return success(gyfDoctorScheduleService.selectGyfDoctorScheduleByScheduleId(scheduleId));
    }

    /**
     * 新增医生排班
     */
    @PreAuthorize("@ss.hasPermi('gyf:paiban_management:add')")
    @Log(title = "医生排班", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GyfDoctorSchedule gyfDoctorSchedule)
    {
        return toAjax(gyfDoctorScheduleService.insertGyfDoctorSchedule(gyfDoctorSchedule));
    }

    /**
     * 修改医生排班
     */
    @PreAuthorize("@ss.hasPermi('gyf:paiban_management:edit')")
    @Log(title = "医生排班", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GyfDoctorSchedule gyfDoctorSchedule)
    {
        return toAjax(gyfDoctorScheduleService.updateGyfDoctorSchedule(gyfDoctorSchedule));
    }

    /**
     * 删除医生排班
     */
    @PreAuthorize("@ss.hasPermi('gyf:paiban_management:remove')")
    @Log(title = "医生排班", businessType = BusinessType.DELETE)
    @DeleteMapping("/{scheduleIds}")
    public AjaxResult remove(@PathVariable Long[] scheduleIds)
    {
        return toAjax(gyfDoctorScheduleService.deleteGyfDoctorScheduleByScheduleIds(scheduleIds));
    }


}
